<?php
class Disciplinas_model extends CI_Model {
    public function __construct() {
        parent::__construct();
        $this->load->config('parametros');
    }
    
    
    public function get_disciplinas_combo() {
       $this->db->where($this->config->item('dbCliente') . $this->config->item('tblLocalIdiomas') . '.codigo', $this->config->item('language'));
       $this->db->order_by($this->config->item('dbCliente') . $this->config->item('tblDisciplinasInfo') . '.nome ASC');  
       $this->db->join($this->config->item('dbCliente') . $this->config->item('tblLocalIdiomas'), $this->config->item('tblLocalIdiomas') . '.id = ' . $this->config->item('tblDisciplinasInfo') . '.local_idiomas_id', 'INNER');
       $this->db->select($this->config->item('tblDisciplinasInfo').'.*');
       $query = $this->db->get($this->config->item('dbCliente') . $this->config->item('tblDisciplinasInfo'));

         if ($query->num_rows() > 0) {
            return $this->_combo_categorias_option($query->result());
        } else {
            return $this->_combo_categorias_option();
        }
    }
    
     private function _combo_categorias_option($dados = array(), $option = array()) {
        $_new_array = array();
        $_new_array[''] = 'Selecionar';
        if (count($dados) > 0) {
            foreach ($dados as $v) {
                $option[$v->id][$v->disciplinas_id] = $v->nome;
            }


            if (count($option) > 0) {
                foreach ($option as $value) {
                    foreach ($value as $ke => $va) {
                        $_new_array[$ke] = $va;
                    }
                }
            }
        }
        return $_new_array;
    }
    
    public function get_disciplina($_id) {
       $this->db->where($this->config->item('dbCliente') . $this->config->item('tblLocalIdiomas') . '.codigo', $this->config->item('language'));
       $this->db->where($this->config->item('dbCliente') . $this->config->item('tblDisciplinasInfo') . '.disciplinas_id', $_id);
       $this->db->join($this->config->item('dbCliente') . $this->config->item('tblLocalIdiomas'), $this->config->item('tblLocalIdiomas') . '.id = ' . $this->config->item('tblDisciplinasInfo') . '.local_idiomas_id', 'INNER');
       $this->db->select($this->config->item('tblDisciplinasInfo').'.*');
       $query = $this->db->get($this->config->item('dbCliente') . $this->config->item('tblDisciplinasInfo'));

         if ($query->num_rows() > 0) {
            return $query->row();
        } else {
            return NULL;
        }
    }
}